package com.entmanage.base.hrm.service.impl;

import com.entmanage.base.hrm.domain.HrmEmployee;
import com.entmanage.base.hrm.mapper.HrmEmployeeMapper;
import com.entmanage.base.hrm.service.EmployeeValidateService;
import com.entmanage.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;

public class EmployeeValidateServiceImpl implements EmployeeValidateService {
    @Autowired
    private HrmEmployeeMapper employeeMapper;

    @Override
    public HrmEmployee validateEmployee(String mobile) {
        // 检查员工是否存在
        HrmEmployee employee = employeeMapper.selectEmployeeByMobile(mobile);
        if (employee == null) {
            throw new ServiceException("员工不存在");
        }

        // 检查是否已关联用户
        if (employee.getUserId() != null) {
            throw new ServiceException("该员工已注册过账号");
        }

        return employee;
    }

}
